package grails4springcloudgreenwich

import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration

import groovy.transform.CompileStatic
import io.micronaut.context.env.Environment
import io.micronaut.spring.context.env.MicronautEnvironment
import org.springframework.cloud.client.discovery.EnableDiscoveryClient
import org.springframework.cloud.openfeign.EnableFeignClients
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Primary
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.web.context.support.StandardServletEnvironment

@ComponentScan
@EnableFeignClients
@EnableDiscoveryClient
@CompileStatic
class Application extends GrailsAutoConfiguration {
    static void main(String[] args) {
        def ctx = GrailsApp.run(Application, args)
        println ctx.environment
    }

    /**
     * Parameter 0 of constructor in org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration required a single bean, but 2 were found:
     * 	- environment: a programmatically registered singleton	- io.micronaut.spring.context.env.MicronautEnvironment(Primary): defined in null
     * @param environment
     * @return
     */
//    @Bean
//    @Primary
//    ConfigurableEnvironment environment1(StandardServletEnvironment environment) {
//        return environment
//    }

    @Bean
    @Primary
    ConfigurableEnvironment environment(MicronautEnvironment environment) {
        return environment
    }
}